@import '../../../components/style/themes/default';
@import '../../../components/style/mixins/index';
@import '../../field/style/mixin';

// size mixins for input
.input-lg() {
  &-lg & {
    height: @input-height-lg;
    padding: @input-padding-vertical-lg @input-padding-horizontal;
  }
}

.input-sm() {
  &-sm & {
    height: @input-height-sm;
    padding: @input-padding-vertical-sm @input-padding-horizontal;
  }
}

// input status
// == when focus or actived
.active(@color: @outline-color) {
  color: @input-active-color;
  border-color: ~`colorPalette('@{color}', 5) `;
  outline: 0;
  // box-shadow: 0 0 @outline-blur-size @outline-width fade(@color, 20%);
}

// == when hoverd
.hover(@color: @input-hover-border-color) {
  border-color: ~`colorPalette('@{color}', 5) `;
}

.disabled() {
  color: @disabled-color;
  background-color: @input-disabled-bg;
  cursor: not-allowed;
  opacity: 1;
  &,
  &:hover {
    border-color: @input-border-color;
  }
}

// Placeholder text
.placeholder(@color: @input-placeholder-color) {
  // Firefox
  &::-moz-placeholder {
    color: @color;
    text-align: left;
    opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
  }
  // Internet Explorer 10+
  &:-ms-input-placeholder {
    color: @color;
    text-align: left;
  }
  // Safari and Chrome
  &::-webkit-input-placeholder {
    color: @color;
    text-align: left;
  }
}

// Basic style for input
.input(@prefix-width: @input-icon-width-base, @suffix-width: @input-icon-width-base) {
  position: relative;
  display: inline-block;
  width: 100%;
  height: @input-height-base;
  padding: @input-padding-vertical-base @input-padding-horizontal;
  color: @input-color;
  font-size: inherit;
  line-height: 1;
  background-color: transparent;
  background-image: none;
  border: @border-width-base @border-style-base @input-border-color;
  border-radius: @border-radius-base;
  cursor: text;
  transition-duration: 0.3s;
  transition-property: opacity, color, background-color, border;

  .placeholder;

  label:hover &,
  &:hover {
    .hover;
  }

  &:focus,
  &-focused & {
    .active;
  }

  &-disabled &,
  &-disabled label:hover &,
  &:disabled {
    .disabled;
  }

  &-disabled &-prefix,
  &-disabled &-suffix,
  &-disabled&-prefix-button &-prefix,
  &-disabled&-suffix-button &-suffix,
  &-disabled &-inner-button,
  &-disabled input {
    cursor: not-allowed;
  }

  &-not-editable & {
    cursor: default;
  }

  &-placeholder,
  &-rendered-value {
    position: absolute;
    top: 0;
    bottom: 0;
    max-width: 100%;
    height: @input-height-base;
    margin: auto 0;
    padding: 0 @input-padding-horizontal;
    line-height: @input-height-base;
    white-space: pre;
    border: @border-width-base @border-style-base transparent;
    transition: all 0.3s;

    &-inner {
      display: inline-block;
      width: 100%;
      overflow: hidden;
    }
  }

  &-placeholder {
    color: @input-placeholder-color;
    white-space: nowrap;
    opacity: 0;
  }

  // Reset height for `textarea`s
  textarea& {
    max-width: 100%; // prevent textearea resize from coming out of its container
    height: auto;
    vertical-align: bottom;
  }

  // Size
  .input-lg;
  .input-sm;

  &-wrapper {
    position: relative;
    display: inline-block;
    line-height: 1;
    vertical-align: middle;
    background-color: @input-wrapper-bg;

    label {
      position: relative;
      z-index: 1;
      display: block;
    }

    .@{field-label-prefix-cls} {
      z-index: -1;
    }
  }

  &-prefix,
  &-suffix,
  &-inner-button {
    position: absolute;
    top: 0.01rem;
    bottom: 0.01rem;
    z-index: 1;
    height: 0.2rem;
    margin: auto 0;
    line-height: 1;
    text-align: center;
  }

  &-prefix {
    left: 0.01rem;
    width: @prefix-width;
  }

  &-suffix {
    width: @suffix-width;
  }

  &-suffix,
  &-inner-button {
    right: 0.01rem;
  }

  &-prefix-button &-placeholder,
  &-prefix-button &-rendered-value {
    padding-left: @prefix-width;
  }

  &-suffix-button &-placeholder,
  &-suffix-button &-rendered-value {
    padding-right: @suffix-width;
  }

  &-suffix-button &-inner-button {
    right: @suffix-width + 0.01rem;
  }

  &-suffix-button &-suffix {
    cursor: pointer;
  }

  &:not(textarea):not(:last-child) {
    padding-right: @suffix-width;
  }

  &:not(textarea):not(:first-child) {
    padding-left: @prefix-width;
  }

  &-inner-button {
    z-index: 1;
    width: @input-button-width;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s;
  }

  &-wrapper:hover &-inner-button,
  &-focused &-inner-button {
    z-index: 2;
    opacity: 1;

    &-clear-button {
      right: @suffix-width;
    }
  }

  &-wrapper:hover &-suffix-button &-suffix,
  &-focused&-suffix-button &-suffix {
    opacity: 1;
  }

  &-clear-button {
    background: transparent;

    &:hover {
      color: @primary-5;
    }

    &:active {
      color: @primary-3;
    }
  }

  &-empty &-clear-button {
    display: none;

    & + * {
      opacity: 1 !important;
    }
  }
  &-empty &-placeholder {
    opacity: 1;
  }

  > ul {
    position: relative;
    margin: 0;
    padding: 0.02rem 0 0 0;
    overflow: hidden auto;

    > li {
      display: inline-block;
      max-width: 99%;
      height: 0.24rem;
      margin-bottom: 0.02rem;
      line-height: 0.22rem;
      vertical-align: middle;
    }
  }

  &-multiple {
    &-value {
      display: block;
      width: 100%;
      height: 0;
      padding: 0;
      border: none;
      visibility: hidden;
    }

    &-input {
      width: 0.05rem;
      max-width: 100%;
      height: 100%;
      margin-left: 0.04rem;
      padding: 0;
      background-color: transparent;
      border: none;
      outline: 0;
    }
  }

  &-multiple & {
    height: auto;
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
    padding-left: 0;
  }

  &-multiple &:not(:last-child) {
    padding-right: @suffix-width * 2;
  }

  &-multiple:not(&-suffix-button) &:not(:last-child) {
    padding-right: @suffix-width;
  }

  &-multiple-block {
    .tag-block;
    cursor: default;

    .@{iconfont-css-prefix} {
      height: 100%;
      margin-left: 0.08rem;
      line-height: inherit;
      cursor: pointer;
    }
  }

  &-range {
    &-text {
      position: relative;
      display: block;
      width: 100%;
      height: 100%;
      white-space: nowrap;
    }

    &-start,
    &-end,
    &-split,
    &-input {
      display: inline-block;
      height: 100%;
      line-height: 0.26rem;
      text-align: center;
    }

    &-start,
    &-end,
    &-input {
      width: ~'calc(50% - .1rem)';
      background-color: transparent;
      border: none;
      outline: 0;
    }

    &-split {
      width: 0.2rem;
    }

    &-input {
      position: absolute;
      color: @primary-color;
      font-weight: bold;
      opacity: 0;
    }
  }
  &-focused &-range-input {
    opacity: 1;
  }

  &-group {
    display: flex;

    &-wrapper {
      display: inline-block;
      width: 100%;
    }

    &-before,
    &-after,
    &-help {
      display: flex;
      align-items: center;
      padding-right: 0.05rem;
      padding-left: 0.05rem;
      word-break: keep-all;
      background-color: @input-addon-bg;
      border: 0.01rem solid @input-border-color;
      border-radius: @border-radius-base;
    }

    &-before {
      border-right: none;
      border-top-right-radius: 0 !important;
      border-bottom-right-radius: 0 !important;
    }

    &-after,
    &-help {
      border-left: none;
      border-top-left-radius: 0 !important;
      border-bottom-left-radius: 0 !important;
    }

    &-help:not(:last-child) {
      border-radius: 0 !important;
    }

    &-input {
      flex: 1;
    }
  }

  &-group-input:not(:last-child) & {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  &-group-input:not(:first-child) & {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  &-group-input &-wrapper {
    width: 100%;
  }

  &:-webkit-autofill {
    box-shadow: 0 0 0 10rem @input-wrapper-bg inset;
  }

  &-required {
    background-color: @input-required-bg;
  }

  .validation;
  .input-underline;
  .float-label(@prefix-width);
  .float-label-input(@prefix-width);

  // transform
  &-uppercase {
    text-transform: uppercase;
  }

  &-lowercase {
    text-transform: lowercase;
  }

  &-capitalize {
    text-transform: capitalize;
  }
}

.float-label-input(@prefix-width) {
  &-float-label & {
    border: none;
  }

  &-float-label::before {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: block;
    border: @border-width-base @border-style-base @input-border-color;
    border-radius: 0.05rem;
    content: ' ';
  }
  &-float-label&-focused::before,
  &-float-label&-invalid::before {
    border-width: 0.02rem;
  }
  &-float-label:hover:not(&-disabled):not(&-focused):not(&-invalid)::before {
    border-color: @input-color;
  }

  &-float-label&-focused::before {
    border-color: @primary-color;
  }
  &-float-label&-invalid::before {
    border-color: @error-color;
  }

  &-float-label&-disabled {
    i {
      color: @disabled-color;
    }
  }

  &-float-label&-disabled::before {
    border-style: dashed;
  }

  &-float-label&-disabled &,
  &-float-label&-disabled &:hover {
    background-color: transparent;
  }

  &-group-input:not(:last-child) &-float-label::before {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  &-group-input:not(:first-child) &-float-label::before {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  &-float-label-group &-group-before,
  &-float-label-group &-group-after,
  &-float-label-group &-group-help {
    border-radius: 4px;
  }
  &-float-label &:-webkit-autofill {
    width: ~'calc(100% - .04rem)';
    height: 0.32rem;
    margin: 0.02rem;
    padding-left: @input-padding-horizontal - 0.02rem;
    border-radius: 0.04rem;
  }

  &-float-label textarea&:-webkit-autofill {
    height: auto;
  }

  &-prefix-button&-float-label &:-webkit-autofill {
    padding-left: @prefix-width - 0.02rem;
  }
}

.input-underline() {
  // underline
  //default underline
  /* stylelint-disable */
  &-underline {
    position: absolute;
    bottom: -@border-width-base;
    width: 100%;
    height: 0;
    border-bottom: @border-width-base @border-style-base @input-baseline-color;
  }

  &-ripple {
    position: absolute;
    left: 0;
    width: 100%;
    height: 0;
    border-bottom: 0.02rem @border-style-base @primary-color;
    transform: scaleX(0.5);
    transform-origin: 50%;
    opacity: 0;
    transition: border-color 300ms cubic-bezier(0.55, 0, 0.55, 0.2);
  }
  //disabled underline
  &-disabled &-underline {
    border-bottom: @border-width-base dotted rgba(0, 0, 0, 0.42);
  }
  // focused underline
  &-focused &-underline &-ripple {
    transform: scaleX(1);
    opacity: 1;
    transition: transform 300ms cubic-bezier(0.25, 0.8, 0.25, 1),
      opacity 100ms cubic-bezier(0.25, 0.8, 0.25, 1),
      border-color 300ms cubic-bezier(0.25, 0.8, 0.25, 1);
  }

  &-invalid &-underline {
    border-color: @error-color;
  }
}

.tag-block() {
  display: inline-block;
  max-width: 99%;
  margin: 0 0.02rem;
  padding: 0 0.08rem;
  overflow: hidden;
  color: @tag-default-color;
  line-height: @line-height-base;
  white-space: nowrap;
  background-color: @tag-default-bg;
  border-radius: @border-radius-base;
  > div {
    height: 100%;
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    vertical-align: top;

    &:not(:last-child) {
      max-width: ~'calc(100% - .24rem)';
    }
  }
  &-invalid {
    background-color: @error-color;
  }
  &-disabled {
    padding-right: 0.1rem;
    background-color: @disabled-color;
    cursor: not-allowed;
  }
}
